/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BookPanel.java
 *
 * Created on 19/11/2009, 14:24:24
 */

package desktopapplication3;

import backend.Product;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

/**
 *
 * @author santiago
 */
public class BookPanel extends javax.swing.JPanel {

    private Product myProd;
    private int languagecode;
    private List<String> pInformation;
    /** Creates new form BookPanel */
    public BookPanel(Product aProd, int lc) {
        initComponents();
        myProd=aProd;
        try {
            pInformation = aProd.getProductInformation();
        } catch (Exception a) {
                org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(desktopapplication3.DesktopApplication3.class).getContext().getResourceMap(VentanaPrincipal.class);
                JOptionPane.showMessageDialog(this,resourceMap.getString("ERROR_"+a.getMessage()),"Error",1);
                System.exit(0);
        }
        languagecode=lc;

        Icon preview=null;
        try {
            URL url = new URL(myProd.getImage());
            preview = new ImageIcon( DesktopApplication3.getScaledImage((new ImageIcon( url )).getImage(),350,395) );
        } catch (MalformedURLException ex) {
                org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(desktopapplication3.DesktopApplication3.class).getContext().getResourceMap(VentanaPrincipal.class);
                JOptionPane.showMessageDialog(this,resourceMap.getString("ERROR_1534"),"Error",1);
                System.exit(0);
        }

        jLabel1.setText(myProd.getName()); // NOI18N
        jLabel2.setIcon(preview);
        auLab.setText(pInformation.get(1)); // NOI18N
        puLab.setText(pInformation.get(2)); // NOI18N
        puDaLab.setText(pInformation.get(3)); // NOI18N
        laLab.setText(pInformation.get(6)); // NOI18N
        productPrice.setText(((Double)(myProd.getPrice())).toString()); // NOI18N
        productRank.setText(((Double)(myProd.getRank())).toString()); // NOI18N
        



        //initMyComponents();
    }

    private void initMyComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        autores = new javax.swing.JLabel();
        editorial = new javax.swing.JLabel();
        fechaPublicacion = new javax.swing.JLabel();
        idioma = new javax.swing.JLabel();
        auLab = new javax.swing.JLabel();
        puLab = new javax.swing.JLabel();
        puDaLab = new javax.swing.JLabel();
        laLab = new javax.swing.JLabel();
        Ranking = new javax.swing.JLabel();
        Precio = new javax.swing.JLabel();
        productPrice = new javax.swing.JLabel();
        productRank = new javax.swing.JLabel();
         Icon preview=null;
        try {
            preview = new ImageIcon(new URL(myProd.getImage()));
        } catch (MalformedURLException ex) {
                org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(desktopapplication3.DesktopApplication3.class).getContext().getResourceMap(VentanaPrincipal.class);
                JOptionPane.showMessageDialog(this,resourceMap.getString("ERROR_1534"),"Error",1);
                System.exit(0);
        }

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(desktopapplication3.DesktopApplication3.class).getContext().getResourceMap(BookPanel.class);
        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText(myProd.getName()); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        //jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setIcon(preview);
        jLabel2.setName("jLabel2"); // NOI18N

        autores.setFont(resourceMap.getFont("autores.font"));
        autores.setText(resourceMap.getString("autores.text")); // NOI18N
        autores.setName("autores"); // NOI18N

        editorial.setFont(resourceMap.getFont("autores.font"));
        editorial.setText(resourceMap.getString("editorial.text")); // NOI18N
        editorial.setName("editorial"); // NOI18N

        fechaPublicacion.setFont(resourceMap.getFont("autores.font"));
        fechaPublicacion.setText(resourceMap.getString("fechaPublicacion.text")); // NOI18N
        fechaPublicacion.setName("fechaPublicacion"); // NOI18N

        idioma.setFont(resourceMap.getFont("autores.font"));
        idioma.setText(resourceMap.getString("idioma.text")); // NOI18N
        idioma.setName("idioma"); // NOI18N

        auLab.setText(pInformation.get(1)); // NOI18N
        auLab.setName("auLab"); // NOI18N

        puLab.setText(pInformation.get(2)); // NOI18N
        puLab.setName("puLab"); // NOI18N

        puDaLab.setText(pInformation.get(3)); // NOI18N
        puDaLab.setName("puDaLab"); // NOI18N

        laLab.setText(pInformation.get(6)); // NOI18N
        laLab.setName("laLab"); // NOI18N

        Ranking.setFont(resourceMap.getFont("Ranking.font")); // NOI18N
        Ranking.setText(resourceMap.getString("Ranking.text")); // NOI18N
        Ranking.setName("Ranking"); // NOI18N

        Precio.setFont(resourceMap.getFont("Precio.font")); // NOI18N
        Precio.setText(resourceMap.getString("Precio.text")); // NOI18N
        Precio.setName("Precio"); // NOI18N

        productPrice.setText(((Double)(myProd.getPrice())).toString()); // NOI18N
        productPrice.setName("productPrice"); // NOI18N

        productRank.setText(((Double)(myProd.getRank())).toString()); // NOI18N
        productRank.setName("productRank"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 696, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(idioma)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(laLab)
                .addContainerGap(547, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(fechaPublicacion)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(puDaLab)
                .addContainerGap(520, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(editorial)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(puLab)
                .addContainerGap(559, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(autores)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(auLab)
                .addContainerGap(571, Short.MAX_VALUE))
            .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 696, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(Ranking)
                        .addGap(18, 18, 18)
                        .addComponent(productRank))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(Precio)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(productPrice)))
                .addContainerGap(559, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(autores)
                    .addComponent(auLab))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(editorial)
                    .addComponent(puLab))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fechaPublicacion)
                    .addComponent(puDaLab))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(idioma)
                    .addComponent(laLab))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Ranking)
                    .addComponent(productRank))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Precio)
                    .addComponent(productPrice))
                .addGap(12, 12, 12))
        );
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        autores = new javax.swing.JLabel();
        editorial = new javax.swing.JLabel();
        fechaPublicacion = new javax.swing.JLabel();
        idioma = new javax.swing.JLabel();
        auLab = new javax.swing.JLabel();
        puLab = new javax.swing.JLabel();
        puDaLab = new javax.swing.JLabel();
        laLab = new javax.swing.JLabel();
        Ranking = new javax.swing.JLabel();
        Precio = new javax.swing.JLabel();
        productPrice = new javax.swing.JLabel();
        productRank = new javax.swing.JLabel();
        productPrice1 = new javax.swing.JLabel();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(desktopapplication3.DesktopApplication3.class).getContext().getResourceMap(BookPanel.class);
        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        autores.setFont(resourceMap.getFont("autores.font")); // NOI18N
        autores.setText(resourceMap.getString("autores.text")); // NOI18N
        autores.setName("autores"); // NOI18N

        editorial.setFont(resourceMap.getFont("autores.font")); // NOI18N
        editorial.setText(resourceMap.getString("editorial.text")); // NOI18N
        editorial.setName("editorial"); // NOI18N

        fechaPublicacion.setFont(resourceMap.getFont("autores.font")); // NOI18N
        fechaPublicacion.setText(resourceMap.getString("fechaPublicacion.text")); // NOI18N
        fechaPublicacion.setName("fechaPublicacion"); // NOI18N

        idioma.setFont(resourceMap.getFont("autores.font")); // NOI18N
        idioma.setText(resourceMap.getString("idioma.text")); // NOI18N
        idioma.setName("idioma"); // NOI18N

        auLab.setText(resourceMap.getString("auLab.text")); // NOI18N
        auLab.setName("auLab"); // NOI18N

        puLab.setText(resourceMap.getString("puLab.text")); // NOI18N
        puLab.setName("puLab"); // NOI18N

        puDaLab.setText(resourceMap.getString("puDaLab.text")); // NOI18N
        puDaLab.setName("puDaLab"); // NOI18N

        laLab.setText(resourceMap.getString("laLab.text")); // NOI18N
        laLab.setName("laLab"); // NOI18N

        Ranking.setFont(resourceMap.getFont("Ranking.font")); // NOI18N
        Ranking.setText(resourceMap.getString("Ranking.text")); // NOI18N
        Ranking.setName("Ranking"); // NOI18N

        Precio.setFont(resourceMap.getFont("Precio.font")); // NOI18N
        Precio.setText(resourceMap.getString("Precio.text")); // NOI18N
        Precio.setName("Precio"); // NOI18N

        productPrice.setFont(resourceMap.getFont("productPrice1.font")); // NOI18N
        productPrice.setForeground(resourceMap.getColor("productPrice.foreground")); // NOI18N
        productPrice.setText(resourceMap.getString("productPrice.text")); // NOI18N
        productPrice.setName("productPrice"); // NOI18N

        productRank.setText(resourceMap.getString("productRank.text")); // NOI18N
        productRank.setName("productRank"); // NOI18N

        productPrice1.setFont(resourceMap.getFont("productPrice1.font")); // NOI18N
        productPrice1.setForeground(resourceMap.getColor("productPrice1.foreground")); // NOI18N
        productPrice1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        productPrice1.setText(resourceMap.getString("productPrice1.text")); // NOI18N
        productPrice1.setName("productPrice1"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 308, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(editorial)
                            .addComponent(autores)
                            .addComponent(fechaPublicacion)
                            .addComponent(idioma)
                            .addComponent(Ranking)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(Precio)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(productPrice1, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(puLab, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(productPrice, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                            .addComponent(productRank, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                            .addComponent(laLab, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                            .addComponent(puDaLab, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                            .addComponent(auLab, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 546, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(autores)
                            .addComponent(auLab))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(editorial)
                            .addComponent(puLab))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(fechaPublicacion)
                            .addComponent(puDaLab))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(idioma)
                            .addComponent(laLab))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(Ranking)
                            .addComponent(productRank))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(Precio)
                            .addComponent(productPrice)
                            .addComponent(productPrice1))
                        .addGap(33, 33, 33))))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Precio;
    private javax.swing.JLabel Ranking;
    private javax.swing.JLabel auLab;
    private javax.swing.JLabel autores;
    private javax.swing.JLabel editorial;
    private javax.swing.JLabel fechaPublicacion;
    private javax.swing.JLabel idioma;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel laLab;
    private javax.swing.JLabel productPrice;
    private javax.swing.JLabel productPrice1;
    private javax.swing.JLabel productRank;
    private javax.swing.JLabel puDaLab;
    private javax.swing.JLabel puLab;
    // End of variables declaration//GEN-END:variables

}
